home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 782 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.1 KB

  1. Path: engnews1.Eng.Sun.COM!usenet
  2. From: clamage@Eng.sun.com (Steve Clamage)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Constructors and conversion operator
  5. Date: 19 Mar 1996 16:40:40 GMT
  6. Organization: Sun Microsystems Inc.
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <4imnnl$j29@engnews1.Eng.Sun.COM>
  9. References: <314E1D5D.76E5@cs.tu-berlin.de>
  10. Reply-To: clamage@Eng.sun.com
  11. NNTP-Posting-Host: taumet.eng.sun.com
  12. X-Nntp-Posting-Host: taumet.eng.sun.com
  13. Content-Length: 1353
  14. X-Lines: 30
  15.  
  16. In article 76E5@cs.tu-berlin.de, Roman Lechtchinsky <wolfro@cs.tu-berlin.de> writes:
  17. >
  18. >The DWP defines:
  19. >
  20. >A constructor declared without the  function-specifier  explicit  that
  21. >  can  be called with a single parameter specifies a conversion from the
  22. >  type of its first parameter to the type of its  class. [class.conv.ctor]
  23. >
  24. >Now, to me this means that a copy constructor is a converting constructor 
  25. >since it takes a single parameter which is a reference to an object of the 
  26. >class ( I don't think that this is intended ). 
  27.  
  28. I don't think it matters. The conversion is the identity conversion. In
  29. places where conversions are required, there is almost always more than
  30. one way to achieve the conversion. (Often there is an infinite number
  31. of possible conversion sequences, such as short->int->short->int->short->...->int.)
  32. The explicit rule in such cases is to choose the shortest possible sequence
  33. of conversions.
  34.  
  35. Suppose a copy constructor T::T(const T&) is viewed as a conversion from T to
  36. T. If such a conversion is "needed", the shortest conversion sequence must be
  37. chosen. That would be the null sequence, and so the copy ctor would never
  38. be used or even considered for that purpose. (Just as the sequence
  39. int->Rational->float would never be considered in converting an int to
  40. a float.)
  41.  
  42. ---
  43. Steve Clamage, stephen.clamage@eng.sun.com
  44.  
  45.  
  46.  
  47. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your
  48.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  49.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  50.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  51.   Comments? mailto:std-c++-request@ncar.ucar.edu
  52. ]
  53.